import { NgModule, SkipSelf, Optional } from '@angular/core';
import { HttpClientModule } from "@angular/common/http";
// svg 使用
import { MatIconRegistry } from "@angular/material";
import { DomSanitizer } from "@angular/platform-browser";

import { SharedModule } from '../shared/shared.module'

import { AppRoutingModule } from "./app-routing.module";

import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { loadSvgResources } from '../utils/svg.util';


@NgModule({
  declarations: [
    HeaderComponent,
    FooterComponent,
    SidebarComponent
  ],
  imports: [
    HttpClientModule,
    SharedModule, // 报错，热编译有问题，重新编译即可
    AppRoutingModule
  ],
  exports: [
    HeaderComponent,
    FooterComponent,
    SidebarComponent,
    AppRoutingModule
  ]
})
export class CoreModule {

  constructor(@Optional() @SkipSelf() parent: CoreModule,
              ir: MatIconRegistry, 
              ds: DomSanitizer){
    if(parent){
      throw new Error("模块已经存在，不能再次加载");
    }
    loadSvgResources(ir,ds);
  }
  
}
